package com.eliza.base.entity.model.user

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Upsert
import com.eliza.library.data.entity.UserEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface UserDao {
    @Query("SELECT * FROM users")
    fun getAllFlow(): Flow<List<UserEntity>>

    @Query("SELECT * FROM users")
    fun getAllNormal(): LiveData<List<UserEntity>>

    @Query("SELECT * FROM users")
    suspend fun getAll(): List<UserEntity>

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insert(users: List<UserEntity>)

    @Query(
        "SELECT * FROM users WHERE name LIKE :name"
    )
    fun getByName(name: String): Flow<List<UserEntity>>

    @Upsert
    suspend fun upsertUsers(entities: List<UserEntity>)

    @Query(
        "SELECT * FROM users WHERE id IN (:ids)"
    )
    fun getByIds(ids: Set<Int>): Flow<List<UserEntity>>

    @Query(
        "SELECT * FROM users WHERE id = :id"
    )
    fun getById(id: Int): Flow<UserEntity>

    @Delete()
    suspend fun deleteById(id: UserEntity)

}